// @charset "utf-8";
var isReqZqxy = false,
	isReqSh = false;
var clientQuoteBase = {
	formatData : function (rst,type,code) {
		var result = JSON.parse(rst);
		var arr = [];
		$.each(result[code], function (i, value) {
			if (value[type] == 'NUL') {
				arr.push(null);
			} else {
				if (code == '1A0001') {
					arr.push(Math.round(value[type]));
				} else {
					arr.push(parseFloat(parseFloat(value[type]).toFixed(2)));
				}
			}
		});
		return arr;
	},
	formatDataSection : function (rst,type,code) {
		var result = JSON.parse(rst);
		var arr = [];
		var date = [];
		$.each(result[code], function (i, value) {
			var time = commonMethod.timeStamp(i * 1000);
			date.push(time.substr(5));
			if (code == '1A0001') {
				arr.push(Math.round(value[type]));
			} else {
				arr.push(parseFloat(parseFloat(value[type]).toFixed(2)));
			}
		});
		var obj = {
			date : date,
			arr : arr
		};
		return obj;
	},
	requestMin: function(code,begin,end,callback){
		var self = this;
		var rst;
		isReqSh = false;
		isReqZqxy = false;
		var getData = function(param){
			var type = '2525646';
			if (code == '1A0001') {
				type = '10';
				isReqSh = true;
			} else {
				isReqZqxy = true;
			}
			rst = commonMethod.thsQuote.getData2({
				type:type,
				code:code,
				period:'min',
				time:{
					begin:begin,
					end:end,
					timeFmt:1	// 这里必须加timeFmt,1表示时间的格式是日期20160405这种格式
				},
				updateMode:1, // 取数据是指定1，否则取不到数据，因为这是用公式取得
				timeStamp:1		// 指定返回的时间是时间戳，默认不是
			});
			// alert('rst='+rst);
			if(rst == null || rst.replace(/\s*$/,"") == 'null'){
				callback('null');
			}else {
				var arr = self.formatData(rst,type,code);
				callback(arr);
			}
		};
		commonMethod.thsQuote.request({
			type:'10,6',
			code: code,
			period:'min',
			begin:begin,
			end:end,
			timeFmt:1,	// 这里必须加timeFmt,1表示时间的格式是日期20160405这种格式
			onready: getData
		});
	},
	requestDay: function(code,begin,end,callback){
		var self = this;
		var getData = function(param){
			var type = '3672520';
			if (code == '1A0001') {
				type = '11';
			}
			var rst = commonMethod.thsQuote.getData2({
				type:type,
				code:code,
				period:'day',
				mode: 'after',
				time:{begin:begin,end:end},
				updateMode:1,
				timeStamp:1
			});
			var result = self.formatDataSection(rst,type,code);
			callback(result);
		};
		commonMethod.thsQuote.request({
			type:'11,6',
			code:code,
			period:'day',
			begin:begin,
			end:end,
			onready: getData
		});
	},
	registerPush : function (date, callback, that) {
		var self = this;
		commonMethod.thsQuote.registerPush({
			code: '883900,1A0001',
			onready: function(result) {
				var zqxyRst = commonMethod.thsQuote.getData2({
					type:'2525646',
					code:'883900',
					period:'min',
					time:{begin:date,end:date,timeFmt:1},
					updateMode:1,
					timeStamp:1
				});
				var shRst = commonMethod.thsQuote.getData2({
					type:'10',
					code:'1A0001',
					period:'min',
					time:{begin:date,end:date,timeFmt:1},
					updateMode:1,
					timeStamp:1
				});
				var zqxyArr = [];
				if(zqxyRst == null || zqxyRst.replace(/\s*$/,"") == 'null'){
					zqxyArr = [];
				}else {
					zqxyArr = self.formatData(zqxyRst,'2525646','883900');
				}

				var shArr = [];
				if(shRst == null || shRst.replace(/\s*$/,"") == 'null'){
					shArr = [];
				}else {
					shArr = self.formatData(shRst,'10','1A0001');
				}

				callback.call(that, zqxyArr, shArr);
			}
		});
	}
};